package com.lee.boot.head.first.demo.socket.client;


import java.io.*;
import java.net.Socket;

public class SocketClient {

    public static void main(String[] args) {
        OutputStream outputStream = null;
        InputStream inputStream = null;
        PrintWriter printWriter = null;
        BufferedReader bufferedReader = null;
        try (Socket socket = new Socket("127.0.0.1", 5500)) {
            outputStream = socket.getOutputStream();
            printWriter = new PrintWriter(outputStream, true);
            printWriter.println("hi");
            inputStream = socket.getInputStream();
            bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
            String s;
            while ((s = bufferedReader.readLine()) != null) {
                System.out.println(s);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
//            try {
//                printWriter.close();
//                outputStream.close();
//                inputStream.close();
//                bufferedReader.close();
//            } catch (IOException e) {
//                e.printStackTrace();
//            }

        }


    }
}
